package calvin.study.rabbitmq.config.mq;

import java.util.HashMap;
import java.util.Map;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicMqConfig {
	
	// 声名交换机,并指定一个交换机类型
	@Bean
	public TopicExchange topicOrderExchange() {
		return new TopicExchange("topic_order_exchange", true, false);
	}
	
	@Bean
	public Queue topicOrderQueue() {
		Map<String, Object> args = new HashMap<>();
		//过期消息投递到死信交换机
		args.put("x-dead-letter-exchange", "dead_letter_direct_exchange");
		//死信队列路由key
		args.put("x-dead-letter-routing-key", "deadletter");
		return new Queue("topic_order_queue", true, false, false, args);
	}
	
	@Bean
	public Binding bindingTopicOrder() {
		return BindingBuilder.bind(topicOrderQueue()).to(topicOrderExchange()).with("order.*");
	}

}
